<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
    <meta charset="UTF-8">
    <title>信息编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" type="image/x-icon" th:href="@{/favicon.ico}"/>
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/common.css}">
    <link rel="stylesheet" th:href="@{/css/animate.min.css}">
    <link rel="stylesheet" th:href="@{/iconfont/iconfont.css}">

    <script src="/lib/layui/layui.js"></script>
    <script src="/lib/jquery/jquery.min.js"></script>
    <script src="/js/common.js"></script>

</head>

<body>



<div class="z-body animated fadeIn">
<form action="" method="post" class="layui-form layui-form-pane">
    <div class="layui-form-item">
        <label for="variable" class="layui-form-label">变量值</label>
        <div class="layui-input-block">
            <input type="text" id="variable" name="variable" readonly="readonly"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label for="levels" class="layui-form-label">报警级别</label>
        <div class="layui-input-block">
            <input type="text" id="levels" name="levels" readonly="readonly"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="groups" class="layui-form-label">报警组</label>
        <div class="layui-input-block">
            <input type="text" id="groups" name="groups"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <!--style="border:none;"-->
    <div class="layui-form-item">
        <label for="recovery" class="layui-form-label">恢复值</label>
        <div class="layui-input-block">
            <input type="text" id="recovery" name="recovery"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="plimit" class="layui-form-label">限值</label>
        <div class="layui-input-block">
            <input type="text" id="plimit" name="plimit"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="describes" class="layui-form-label">报警描述</label>
        <div class="layui-input-block">
            <input type="text" id="describes" name="describes"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input">
        </div>
    </div>


        <div style="margin: 0 auto; text-align: center">
            <button id="btn-edit"  type="button" class="layui-btn">修改</button>
        </div>


</form>
</div>

<script>

    function GetRequest() {
        var url = decodeURI(location.search); //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {//判断url是否有参数
            var str = url.substr(1);
            strs = str.split("&");//多个参数时进行拆分
            for (var i = 0; i < strs.length; i++) {//按照等号进行再次拆分
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }

    var Request = undefined;
    Request = GetRequest();
    var id = Request["id"];


    $(document).ready(function () {
        showChakan();
    });
    // alert(id);

    /*数据回显*/
    $.ajax({
        url: "/pu/selectById?id="+id,
        type: "get",
        dataType: "json",
        success: function (json) {
            // alert(id);
            console.log("啦啦啦",json);
            $("#variable").val(json.data.variable);
            $("#groups").val(json.data.groups);
            $("#levels").val(json.data.levels);
            $("#recovery").val(json.data.recovery);
            $("#plimit").val(json.data.plimit);
            $("#describes").val(json.data.describes);
            // console.log("dddddd",json.data[0].details);
            // var deta = json.data[0].details;
            // $("#details").val(deta);
            // layedit.sync(json.data[0].details);
            // console.log("你知不知道",layedit.setContent(Content,json.data[0].details))
            // $("#details").text("要放入富文本的内容");   //富文本编辑
            // layedit.setContent(index, json.data[0].details);       //富文本编辑

        }
    });


    /*编辑*/
    $("#btn-edit").click(function () {

        var variable = $("#variable").val();
        var groups = $("#groups").val();
        var levels = $("#levels").val();
        var recovery = $("#recovery").val();
        var plimit = $("#plimit").val();
        var describes = $("#describes").val();
        // alert(variable);
        // alert(groups);
        // alert(levels);
        // alert(recovery);
        // alert(plimit);
        // alert(describes);
        $.ajax({
            url: "/pu/updateById",
            data: {"id": id,"variable": variable, "groups": groups,"levels": levels,"recovery": recovery, "plimit": plimit,"describes": describes},
            type: "post",
            dataType: "json",
            success: function (json) {

                if (json.state == 2000) {
                    alert("修改成功！");
                    // location.href = "/pu/pupdate";

                } else {
                    alert(json.message);
                }
            }
        });
    });

</script>


</body>

</html>